﻿using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;

namespace 前端系统
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>

    public partial class MainWindow : Window
    {
        //---------------------->>>预加载图片素材
        readonly BitmapImage Exit_Enter = new BitmapImage(new Uri("Img/Exit_2.png", UriKind.Relative));
        readonly BitmapImage Exit_Leave = new BitmapImage(new Uri("Img/Exit_1.png", UriKind.Relative));
        readonly BitmapImage TextBox_Enter = new BitmapImage(new Uri("Img/userbox_2.png", UriKind.Relative));
        readonly BitmapImage TextBox_Leave = new BitmapImage(new Uri("Img/userbox_1.png", UriKind.Relative));
        readonly BitmapImage LoginButton_Enter = new BitmapImage(new Uri("Img/login_Button_2.png", UriKind.Relative));
        readonly BitmapImage LoginButton_Leave = new BitmapImage(new Uri("Img/login_Button_1.png", UriKind.Relative));


        
        static int Head = 0;                 //检测窗口准备移动前是否处于需要MouseUp的状态，值为：1时不进入窗口移动状态



        public MainWindow()                  //入口主函数
        {
            InitializeComponent();
        }



        public void WindowCenter()           //设置窗口屏幕居中
        {
            Top = (SystemParameters.PrimaryScreenHeight - 550) / 2;
            Left = (SystemParameters.PrimaryScreenWidth - Width) / 2;
        }



        //---------------------->>>窗口创建完毕事件
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowCenter();
            (StartGrid.FindResource("StartTo") as Storyboard).Begin(this);
        }



        //---------------------->>>登录事件，点击登录按钮后的事件
        public void UserLogin() 
        {
            Loading_Grid.Width = 290;
            Back_Grid.Width = 290;
            //MessageBox.Show("Welcome!");
            (Right_Grid.FindResource("Loading_Enter") as Storyboard).Begin(this);
            (Loading_Grid.FindResource("Loading_Start") as Storyboard).Begin(this);

            AKui.Delay(4000);

            Loading_Text.Content = "登录失败";

            (Loading_Grid.FindResource("Loading_Error") as Storyboard).Begin(this);

        }



        //---------------------->>>窗口按下事件，用于窗口自由移动
        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (Login_Button.Source == LoginButton_Enter) { return; }
            if (Exit_Img.Source == Exit_Enter) { return; }
            if (Head == 1) { return; }

            FouceBox.Focus();

            this.DragMove();
        }




        //----------------------------------------------------------------->>>>以下是登录窗口各种事件<<<<-------------------------------------------------------

        //---------------------->>>以下是退出按钮的各种事件
        private void Exit_MouseEnter(object sender, MouseEventArgs e)
        {
            Exit_Img.Source = Exit_Enter;
        }

        private void Exit_MouseLeave(object sender, MouseEventArgs e)
        {
            Exit_Img.Source = Exit_Leave;
        }

        private void Exit_Img_MouseUp(object sender, MouseEventArgs e)
        {
            (StartGrid.FindResource("ExitTo") as Storyboard).Begin(this);
            AKui.Delay(1100);
            this.Close();
        }



        //---------------------->>>以下是六边形头像Img的各种事件
        private void Head_MouseEnter(object sender, MouseEventArgs e)
        {
            (Head_Img.FindResource("Head_Show") as Storyboard).Begin(this);
            Head = 1;
        }

        private void Head_MouseLeave(object sender, MouseEventArgs e)
        {
            (Head_Img.FindResource("Head_Hide") as Storyboard).Begin(this);
            Head = 0;
        }

        private void Head_MouseUp(object sender, MouseButtonEventArgs e)
        {
            FouceBox.Focus();
            (Head_Img.FindResource("Head_Mobile") as Storyboard).Begin(this);
        }



        //---------------------->>>以下是登录界面，用户名输入框的事件
        private void UserName_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            UserName_Img.Source = TextBox_Enter;
            UserName_Img.Opacity = 1;
        }

        private void UserName_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            UserName_Img.Source = TextBox_Leave;
            UserName_Img.Opacity = 0.8;
        }

        private void UserName_Box_GotFocus(object sender, RoutedEventArgs e)
        {
            if (UserName_Box.Text == "用户名/邮箱")
            {
                UserName_Box.Text = "";
                UserName_Box.FontSize = 17;
                UserName_Box.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }

        }

        private void UserName_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (UserName_Box.Text == "")
            {
                UserName_Box.Text = "用户名/邮箱";
                UserName_Box.FontSize = 14;
                UserName_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            }
        }



        //---------------------->>>以下是登录界面，密码输入框的事件
        private void UserPass_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            UserPass_Img.Source = TextBox_Enter;
            UserPass_Img.Opacity = 1;
        }

        private void UserPass_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            UserPass_Img.Source = TextBox_Leave;
            UserPass_Img.Opacity = 0.8;
        }

        private void UserPass_Box_GotFocus(object sender, RoutedEventArgs e)
        {
 
            UserPass_Box_Text.Content = "";
            
        }

        private void UserPass_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (UserPass_Box.Password == "")
            {
                UserPass_Box_Text.Content = "密码";
            }
        }

        private void UserPass_Box_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                FouceBox.Focus();
                UserLogin();
            }
        }



        //---------------------->>>以下是登录按钮事件
        private void Login_Button_MouseEnter(object sender, MouseEventArgs e)
        {
            Login_Button.Source = LoginButton_Enter;
        }

        private void Login_Button_MouseLeave(object sender, MouseEventArgs e)
        {
            Login_Button.Source = LoginButton_Leave;
        }

        private void Login_Button_MouseUp(object sender, MouseButtonEventArgs e)
        {
            FouceBox.Focus();
            UserLogin();
        }



        //---------------------->>>以下是主窗口的注册按钮事件
        private void Register_Button_MouseEnter(object sender, MouseEventArgs e)
        {
            Head = 1;
        }

        private void Register_Button_MouseLeave(object sender, MouseEventArgs e)
        {
            Head = 0;
        }

        private void Register_Button_MouseUp(object sender, MouseButtonEventArgs e)
        {
            
            (Right_Grid.FindResource("Login_To_Register_1") as Storyboard).Begin(this);
            (Right_Grid.FindResource("Login_To_Register_2") as Storyboard).Begin(this);

            UserName_Box.Text = ""; UserPass_Box.Password = "";
            UserName_Box.Text = "用户名/邮箱";
            UserName_Box.FontSize = 14;
            UserName_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            UserPass_Box_Text.Content = "密码";
        }



        //---------------------->>>以下是主窗口的找回密码按钮事件
        private void Retrieve_Button_MouseEnter(object sender, MouseEventArgs e)
        {
            Head = 1;
        }

        private void Retrieve_Button_MouseLeave(object sender, MouseEventArgs e)
        {
            Head = 0;
        }

        private void Retrieve_Button_MouseUp(object sender, MouseButtonEventArgs e)
        {
            (Right_Grid.FindResource("Login_To_Retrieve_1") as Storyboard).Begin(this);
            (Right_Grid.FindResource("Login_To_Retrieve_2") as Storyboard).Begin(this);

            UserName_Box.Text = ""; UserPass_Box.Password = "";
            UserName_Box.Text = "用户名/邮箱";
            UserName_Box.FontSize = 14;
            UserName_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            UserPass_Box_Text.Content = "密码";
        }




        //----------------------------------------------------------------->>>>以下是注册窗口各种事件<<<<-------------------------------------------------------

        //---------------------->>>以下是注册界面的注册按钮事件
        private void Register_MouseEnter(object sender, MouseEventArgs e)
        {
            Register.Background = new SolidColorBrush(Color.FromRgb(83, 145, 255));
            Head = 1;
        }

        private void Register_MouseLeave(object sender, MouseEventArgs e)
        {
            Register.Background = new SolidColorBrush(Color.FromRgb(30, 111, 255));
            Head = 0;
        }



        //---------------------->>>以下是注册界面的返回按钮事件
        private void Back_Login_MouseEnter(object sender, MouseEventArgs e)
        {
            Back_Login.Background = new SolidColorBrush(Color.FromRgb(232, 232, 232));
            Head = 1;
        }

        private void Back_Login_MouseLeave(object sender, MouseEventArgs e)
        {
            Back_Login.Background = new SolidColorBrush(Color.FromRgb(247, 247, 247));
            Head = 0;
        }

        private void Back_Login_MouseUp(object sender, MouseButtonEventArgs e)
        {
            (Right_Grid.FindResource("Register_To_Login_1") as Storyboard).Begin(this);
            (Right_Grid.FindResource("Register_To_Login_2") as Storyboard).Begin(this);

            RegisterName_Box.Text = ""; RegisterPass_Box.Password = "";
            RegisterEmail_Box.Text = ""; RegisterKey_Box.Text = "";
            RegisterPass_Box_Text.Content = "密码";
            RegisterKey_Box.Text = "卡密";
            RegisterKey_Box.FontSize = 14;
            RegisterKey_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            RegisterEmail_Box.Text = "邮箱";
            RegisterEmail_Box.FontSize = 14;
            RegisterEmail_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            RegisterName_Box.Text = "用户名";
            RegisterName_Box.FontSize = 14;
            RegisterName_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));

        }



        //---------------------->>>以下是注册界面的卡密输入框事件
        private void RegisterKey_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            RegisterKey_Img.Source = TextBox_Enter;
            RegisterKey_Img.Opacity = 1;
        }

        private void RegisterKey_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            RegisterKey_Img.Source = TextBox_Leave;
            RegisterKey_Img.Opacity = 0.8;
        }

        private void RegisterKey_Box_GotFocus(object sender, RoutedEventArgs e)
        {
            if (RegisterKey_Box.Text == "卡密")
            {
                RegisterKey_Box.Text = "";
                RegisterKey_Box.FontSize = 17;
                RegisterKey_Box.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }

        }

        private void RegisterKey_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (RegisterKey_Box.Text == "")
            {
                RegisterKey_Box.Text = "卡密";
                RegisterKey_Box.FontSize = 14;
                RegisterKey_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            }
        }



        //---------------------->>>以下是注册界面的密码输入框事件
        private void RegisterPass_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            RegisterPass_Img.Source = TextBox_Enter;
            RegisterPass_Img.Opacity = 1;
        }

        private void RegisterPass_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            RegisterPass_Img.Source = TextBox_Leave;
            RegisterPass_Img.Opacity = 0.8;
        }

        private void RegisterPass_Box_GotFocus(object sender, RoutedEventArgs e)
        {
            RegisterPass_Box_Text.Content = "";
        }

        private void RegisterPass_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (RegisterPass_Box.Password == "")
            {
                RegisterPass_Box_Text.Content = "密码";
            }
        }



        //---------------------->>>以下是注册界面的邮箱输入框事件
        private void RegisterEmail_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            RegisterEmail_Img.Source = TextBox_Enter;
            RegisterEmail_Img.Opacity = 1;
        }

        private void RegisterEmail_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            RegisterEmail_Img.Source = TextBox_Leave;
            RegisterEmail_Img.Opacity = 0.8;
        }

        private void RegisterEmail_Box_GotFocus(object sender, RoutedEventArgs e)
        {
            if (RegisterEmail_Box.Text == "邮箱")
            {
                RegisterEmail_Box.Text = "";
                RegisterEmail_Box.FontSize = 17;
                RegisterEmail_Box.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }

        }

        private void RegisterEmail_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (RegisterEmail_Box.Text == "")
            {
                RegisterEmail_Box.Text = "邮箱";
                RegisterEmail_Box.FontSize = 14;
                RegisterEmail_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            }
        }



        //---------------------->>>以下是注册界面的用户名输入框事件
        private void RegisterName_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            RegisterName_Img.Source = TextBox_Enter;
            RegisterName_Img.Opacity = 1;
        }

        private void RegisterName_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            RegisterName_Img.Source = TextBox_Leave;
            RegisterName_Img.Opacity = 0.8;
        }

        private void RegisterName_Box_GotFocus(object sender, RoutedEventArgs e)
        {
            if (RegisterName_Box.Text == "用户名")
            {
                RegisterName_Box.Text = "";
                RegisterName_Box.FontSize = 17;
                RegisterName_Box.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }

        }

        private void RegisterName_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (RegisterName_Box.Text == "")
            {
                RegisterName_Box.Text = "用户名";
                RegisterName_Box.FontSize = 14;
                RegisterName_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            }
        }



        //----------------------------------------------------------------->>>>以下是找回密码窗口各种事件<<<<-------------------------------------------------------

        //---------------------->>>以下是找回密码窗口的修改按钮事件
        private void Retrieve_MouseEnter(object sender, MouseEventArgs e)
        {
            Retrieve.Background = new SolidColorBrush(Color.FromRgb(83, 145, 255));
            Head = 1;
        }

        private void Retrieve_MouseLeave(object sender, MouseEventArgs e)
        {
            Retrieve.Background = new SolidColorBrush(Color.FromRgb(30, 111, 255));
            Head = 0;
        }



        //---------------------->>>以下是找回密码窗口的返回按钮事件
        private void Retrieve_Back_Login_MouseEnter(object sender, MouseEventArgs e)
        {
            Retrieve_Back_Login.Background = new SolidColorBrush(Color.FromRgb(232, 232, 232));
            Head = 1;
        }

        private void Retrieve_Back_Login_MouseLeave(object sender, MouseEventArgs e)
        {
            Retrieve_Back_Login.Background = new SolidColorBrush(Color.FromRgb(247, 247, 247));
            Head = 0;
        }

        private void Retrieve_Back_Login_MouseUp(object sender, MouseButtonEventArgs e)
        {
            (Right_Grid.FindResource("Retrieve_To_Login_1") as Storyboard).Begin(this);
            (Right_Grid.FindResource("Retrieve_To_Login_2") as Storyboard).Begin(this);

            RetrieveCode_Box.Text = ""; RetrieveName_Box.Text = ""; RetrievePass_Box.Text = "";
            RetrieveCode_Box.Text = "验证码";
            RetrieveCode_Box.FontSize = 14;
            RetrieveCode_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            RetrievePass_Box.Text = "新密码";
            RetrievePass_Box.FontSize = 14;
            RetrievePass_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            RetrieveName_Box.Text = "用户名/邮箱";
            RetrieveName_Box.FontSize = 14;
            RetrieveName_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
        }



        //---------------------->>>以下是找回密码窗口的验证码输入框&获取验证码按钮的事件
        private void RetrieveCode_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            RetrieveCode_Img.Source = TextBox_Enter;
            RetrieveCode_Img.Opacity = 1;
        }

        private void RetrieveCode_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            RetrieveCode_Img.Source = TextBox_Leave;
            RetrieveCode_Img.Opacity = 0.8;
        }

        private void RetrieveCode_Box_GotFocus(object sender, RoutedEventArgs e)
        {
            if (RetrieveCode_Box.Text == "验证码")
            {
                RetrieveCode_Box.Text = "";
                RetrieveCode_Box.FontSize = 17;
                RetrieveCode_Box.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }

        }

        private void RetrieveCode_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (RetrieveCode_Box.Text == "")
            {
                RetrieveCode_Box.Text = "验证码";
                RetrieveCode_Box.FontSize = 14;
                RetrieveCode_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            }
        }

        private void CodeButton_MouseEnter(object sender, MouseEventArgs e)
        {
            CodeButton.Background = new SolidColorBrush(Color.FromRgb(83, 145, 255));
            Head = 1;
        }

        private void CodeButton_MouseLeave(object sender, MouseEventArgs e)
        {
            CodeButton.Background = new SolidColorBrush(Color.FromRgb(30, 111, 255));
            Head = 0;
        }



        //---------------------->>>以下是找回密码窗口的新密码输入框事件
        private void RetrievePass_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            RetrievePass_Img.Source = TextBox_Enter;
            RetrievePass_Img.Opacity = 1;
        }

        private void RetrievePass_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            RetrievePass_Img.Source = TextBox_Leave;
            RetrievePass_Img.Opacity = 0.8;
        }

        private void RetrievePass_Box_GotFocus(object sender, RoutedEventArgs e)
        {
            if (RetrievePass_Box.Text == "新密码")
            {
                RetrievePass_Box.Text = "";
                RetrievePass_Box.FontSize = 17;
                RetrievePass_Box.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }

        }

        private void RetrievePass_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (RetrievePass_Box.Text == "")
            {
                RetrievePass_Box.Text = "新密码";
                RetrievePass_Box.FontSize = 14;
                RetrievePass_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            }
        }



        //---------------------->>>以下是找回密码窗口的用户名输入框事件
        private void RetrieveName_Box_MouseEnter(object sender, MouseEventArgs e)
        {
            RetrieveName_Img.Source = TextBox_Enter;
            RetrieveName_Img.Opacity = 1;
        }

        private void RetrieveName_Box_MouseLeave(object sender, MouseEventArgs e)
        {
            RetrieveName_Img.Source = TextBox_Leave;
            RetrieveName_Img.Opacity = 0.8;
        }

        private void RetrieveName_Box_GotFocus(object sender, RoutedEventArgs e)
        {
            if (RetrieveName_Box.Text == "用户名/邮箱")
            {
                RetrieveName_Box.Text = "";
                RetrieveName_Box.FontSize = 17;
                RetrieveName_Box.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            }

        }

        private void RetrieveName_Box_LostFocus(object sender, RoutedEventArgs e)
        {
            if (RetrieveName_Box.Text == "")
            {
                RetrieveName_Box.Text = "用户名/邮箱";
                RetrieveName_Box.FontSize = 14;
                RetrieveName_Box.Foreground = new SolidColorBrush(Color.FromRgb(127, 127, 127));
            }
        }




        //----------------------------------------------------------------->>>>以下是加载窗口各种事件<<<<-------------------------------------------------------

        //---------------------->>>以下是加载窗口的按钮事件
        private void Loading_Button_MouseEnter(object sender, MouseEventArgs e)
        {
            Loading_Button.Background = new SolidColorBrush(Color.FromRgb(83, 145, 255));
            Head = 1;
        }

        private void Loading_Button_MouseLeave(object sender, MouseEventArgs e)
        {
            Loading_Button.Background = new SolidColorBrush(Color.FromRgb(30, 111, 255));
            Head = 0;
        }

        private void Loading_Button_MouseUp(object sender, MouseButtonEventArgs e)
        {
            (Loading_Grid.FindResource("Loading_Exit") as Storyboard).Begin(this);
            (Right_Grid.FindResource("Loading_Leave") as Storyboard).Begin(this);
            AKui.Delay(600);
            Loading_Grid.Width = 0;
            Back_Grid.Width = 0;
        }

    }
}
